<?php
require_once('./class/Participant.php');
require_once('./class/Evenement.php');

switch (@$_GET['action']){
    default:
        echo _PARTICIPANT_;
    break;

    case "addForm":
        echo Participant::getAddForm();
        break;

    case "doAdd":
        $p = new Participant();
        $p->setId($_POST['id_individu']);
        $p->setIdEvenement($_POST['id_evenement']);
        $p->addOrModify();
        echo _PARTICIPANT_." "._ADDED_;
        break;
         
    case "list":
        $id_evenement = (isset($_GET['id_evenement'])) ? $_GET['id_evenement'] : null;
        $participant_array = Participant::getAllParticipant($id_evenement);
        $html = '<table class="tablesorter">
        							<thead>
        								<th>'._ID_INDIVIDU_.'</th>
        								<th>'._NOM_INDIVIDU_.'</th>
        								<th>'._PRENOM_INDIVIDU_.'</th>
        								<th>'._ID_EVENEMENT_.'</th>
        								<th>'._NOM_EVENEMENT_.'</th>
        								<th>'._DELETE_.'</th>
        							</thead><tbody>';
        $i = 0;
        foreach($participant_array as $p){
            $e = Evenement::getEvenement($p->getIdEvenement());
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
        								<td>'.$p->getIdIndividu().'</td>
        								<td>'.$p->getNom().'</td>
        								<td>'.$p->getPrenom().'</td>
        								<td>'.$p->getIdEvenement().'</td>
        								<td>'.$e->getNom().'</td>
        							<td><a href="?module=participant&action=delete&id_individu='.$p->getIdIndividu().'&id_evenement='.$p->getIdEvenement().'">'._DELETE_.'</a></td>
        						</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;

    case "delete":
        $p = Participant::getParticipant($_GET['id_individu']);
        $p->setIdEvenement($_GET['id_evenement']);
        $p->delete();
        echo _PARTICIPANT_.' '._DELETED_;
        break;
}
?>
